/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.rh.game.loader;

import com.rh.util.Parser;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 *
 * @author hjones
 */
public class ShowImageBuffer extends AbstractXmlBuffer {
    public ShowImageBuffer()  {
        super();
        init();
    }
    
    private String defaultImage = "";
    public String getDefaultImage()  { return defaultImage; }
    private String image = "";
    private List<String> conditions = new ArrayList<String>();
    
    private LinkedHashMap<String, List<String>> special = new LinkedHashMap<String, List<String>>();
    public LinkedHashMap<String, List<String>> getSpecial()  { return special; }
    
    void init()  {
        defaultImage = "";
        special = new LinkedHashMap<String, List<String>>();
    }
    
    @Override
    void characters(String pValue) {
        pValue = Parser.trim(pValue);
        if (pValue.length() == 0)  return;
        debug(getStartElement() + " := " + pValue);
        if ("Condition".equals(getStartElement()))  {
            conditions.add(pValue);
        }
        else if ("ChatImage".equals(getStartElement()))  {
            image = pValue;
        }
    }

    private static void debug(Object o)  {
        // System.out.println("ShowImageBuffer: " + o);
    }
    
    @Override
    void endElement(String pName)  {
        debug("endElement " + pName + ", " + conditions + ", " + image);
        if ("chat".equals(pName))  {
            if (conditions.size() > 1)  {
                special.put(image, conditions);
            }
            else if (conditions.size() == 1)  {
                String x = conditions.get(0);
                if ("DEFAULT".equals(x))  {
                    defaultImage = image;
                    debug("DefaultImage: " + defaultImage);
                }
                else  {
                    special.put(image, conditions);
                }
            }
            
            conditions = new ArrayList<String>();                
        }
    }        
}
